Hibernate is a powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent objects following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. Extremely fine-grained, richly typed object models are possible. Hibernate 2.1 features support for plugin cache providers and is designed to integrate with distributed caches (2.1 also implements more aggressive use of the cache). net.sf.hibernate.cache.CacheProvider is the extension point for user-defined cache integration. Hibernate 2.1.1 or higher is required. hibernate.cache.provider_classOSCache and Hibernate 2.1 integrate though OSCacheProvider.
To enable OSCache in Hibernate's configuration, add the following line to hibernate.cfg.xml: hibernate.cfg.xml <property name="hibernate.cache.provider_class">my.patched.provider.package.OSCacheProvider</property> The default refresh period is CacheEntry.INDEFINITE_EXPIRY. The first time a cacheable query is done, the cache has no effect on speed. On the second and successive queries, the cache will be populated and available to be hit.
Cache Region ConfigurationTo modify the refresh period, CRON expression, add the region configuration to your oscache.properties file, as demonstrated below: [region].refresh.period = 4000 [region].cron = * * 31 Feb * # The maximum cache capacity can only be set per region if you use the # net.sf.hibernate.cache.OSCacheProvider distributed with Hibernate. [region].capacity = 5000 # The patched version distributed with OSCache only allows a single cache.capacity setting and saves memory. The com.mypackage.domain.Customer is Hibernate's internal cache region, which defaults to the classname, and which can be altered by setting Hibernate's configuration property hibernate.cache.region_prefix . Source Code |